package com.ruoyi.web.controller.activiti;
import com.ruoyi.act.domain.QUERY.ActTaskStartQY;
import com.ruoyi.act.service.ActTaskService;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/act/TaskController")
public class ActTaskController {
    @Autowired
    private ActTaskService taskService;

    /**
     * 启动流程实例
     * @param taskStartQUERY
     * @return
     */
    @PostMapping("/start")
    public AjaxResult start(@RequestBody ActTaskStartQY taskStartQUERY){
        return taskService.start(taskStartQUERY);
    };

    /**
     * 获取任务
     * @param userName
     * @return
     */
    @GetMapping("/tasks")
    public AjaxResult tasks(@RequestParam(value = "userName",required = false) String userName){
        String param = SecurityUtils.getUsername();
        if(StringUtils.isNotEmpty(userName)){
            param = userName;
        }
        return taskService.tasks(param);
    };

    /**
     * 完成任务
     * @param id 任务id
     * @return
     */
    @GetMapping("/completeTask")
    public AjaxResult completeTask(@RequestParam("id") String id){
        return taskService.completeTask(id);
    };

    /**
     * 获取任务节点
     * @param id 任务id
     * @return
     */
    @GetMapping("/getHistoryTask")
    public AjaxResult getHistoryTask(@RequestParam("id") String id){
        return taskService.getHistoryTask(id);
    };
}
